<template>
	<view class="template-build tn-safe-area-inset-bottom">
	<!-- 顶部自定义导航 -->
	<tn-nav-bar fixed alpha customBack>
	  <view slot="back" class='tn-custom-nav-bar__back'>
		<text class='icon tn-icon-left' @tap="goBack"></text>
		<text class='icon tn-icon-home-capsule-fill' @tap="backIndex"></text>
	  </view>
	</tn-nav-bar>
    
    <view class="tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      
	  <view class="content" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
		  <scroll-view scroll-y="true" class="scroll-Y" :style="{height: windowHeight + 'px'}">
			<rich-text class="scroll-view-item" :nodes="formData.signContent"></rich-text>
		  </scroll-view>
	  </view>
	  
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl" style="color: red;">甲方</view>
	  <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
	  	<input name="input" :value="formData.companyName" disabled></input>
	  </view>
	  
	  <view class="justify-content-item tn-margin tn-text-bold tn-text-xl" style="color: red;">乙方</view>
	  <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
	  	<input v-model="formData.name" placeholder="请输入真实姓名" placeholder-style="color:#AAAAAA"></input>
	  </view>
	  
	  <view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
	  	<input v-model="formData.idCard" placeholder="请输入身份证号码" placeholder-style="color:#AAAAAA"></input>
	  </view>
      
    </view>
    
    <!-- 悬浮按钮-->
    <view class="tn-flex tn-footerfixed">
      <view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center" @click="confirmAgreement()">
        <tn-button shape="round" backgroundColor="#ff3d57" padding="40rpx 0" width="70%" shadow fontBold>
          <text class="tn-color-white" style="font-size: 16px;">我已确认协议</text>
        </tn-button>
      </view>
    </view>
	  
	</view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
    name: 'TemplateBuild',
    mixins: [template_page_mixin],
		data() {
			return {
				// action: '',
				windowHeight: 0,   //可操作页面高度
				formData: {
					//id: '',
					phone: '',
					//signingStatus: '0',//签约状态：0-未签约，1-已签约
					companyId: '',
					//companyName: '',
					//companyCode: '',
					businessId: '',
					//businessName: '',
					tenantId: '',
					//signingService: '',
					signingServiceId: '',
					//releaseDate: '',
					//signContent: '',
					name: '',
					idCard: '',
				},
				userInfo:{
					avatarUrl: '',
					nickName: '',
					phone: ''
				},
			}
		},
		onLoad(e) {
			if(!e.memberInfo){
				uni.showToast({title: "数据错误！",icon: "none",mask: true,});
				return;
			}
			this.formData = JSON.parse(decodeURIComponent(e.memberInfo));
			// console.log("==2=formData===：",JSON.stringify(this.formData));
			// 获取窗口信息
			let getWindowInfo = uni.getWindowInfo()
			this.windowHeight = (getWindowInfo.windowHeight*0.4).toFixed(0)//可操作页面高度
		},
		methods: {
			confirmAgreement(){
				if(!this.formData.name){
					uni.showToast({title: "请输入真实姓名！",icon: "none",mask: true,});
					return;
				}
				if(!this.formData.idCard){
					uni.showToast({title: "请输入身份证号！",icon: "none",mask: true,});
					return;
				}else{
					let age = this.getAge(this.formData.idCard);
					if(age < 16 || age > 65){
						uni.showToast({title: "身份证年龄不符合报税要求(16-65岁)",icon: "none",mask: true,});
						return;
					}
				}
				
				uni.reLaunch({
					url: '/signingPages/uplouIdCard?memberInfo=' + encodeURIComponent(JSON.stringify(this.formData))
				});
			},
			
			//根据身份证号获取年龄
			getAge(identityCard) {
			    var len = (identityCard + "").trim().length;
			    if (len == 0) {
			        uni.showToast({title: "身份证号格式错误！",icon: "none",mask: true,});
			        return;
			    } else {
			        if ((len != 15) && (len != 18)) //身份证号码只能为15位或18位其它不合法
			        {
						uni.showToast({title: "身份证号格式错误！",icon: "none",mask: true,});
			            return;
			        }
			    }
			    var strBirthday = "";
			    if (len == 18) //处理18位的身份证号码从号码中得到生日和性别代码
			    {
			        strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
			    }
			    if (len == 15) {
			        strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
			    }
			    //时间字符串里，必须是“/”
			    var birthDate = new Date(strBirthday);
			    var nowDateTime = new Date();
			    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
			    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
			    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
			        age--;
			    }
			    return age;
			},
			goBack(e){
				uni.reLaunch({
					url: '/signingPages/taskdetails?memberInfo=' + encodeURIComponent(JSON.stringify(this.formData))
				});
			},
			backIndex(e){
				uni.reLaunch({
					url: '/pages/index'
				});
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.template-edit{
	}
  /* 胶囊*/
  .tn-custom-nav-bar__back {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 1000rpx;
    border: 1rpx solid rgba(255, 255, 255, 0.5);
    color: #FFFFFF;
    font-size: 18px;
    
    .icon {
      display: block;
      flex: 1;
      margin: auto;
      text-align: center;
    }
    
    &:before {
      content: " ";
      width: 1rpx;
      height: 110%;
      position: absolute;
      top: 22.5%;
      left: 0;
      right: 0;
      margin: auto;
      transform: scale(0.5);
      transform-origin: 0 0;
      pointer-events: none;
      box-sizing: border-box;
      opacity: 0.7;
      background-color: #FFFFFF;
    }
  }
  
  /* 底部悬浮按钮 start*/
  .tn-tabbar-height {
  	min-height: 100rpx;
  	height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  }
  .tn-footerfixed {
    position: fixed;
    width: 100%;
    bottom: calc(30rpx + env(safe-area-inset-bottom));
    z-index: 1024;
    box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
    
  }
  /* 底部悬浮按钮 end*/
  
  /* 标签内容 start*/
  .tn-tag-content {
    &__item {
      display: inline-block;
      line-height: 45rpx;
      padding: 10rpx 30rpx;
      margin: 20rpx 20rpx 5rpx 0rpx;
      
      &--prefix {
        padding-right: 10rpx;
      }  
    }
  }
  /* 标签内容 end*/
</style>